package org.geometerplus.android.fbreader;

import org.geometerplus.fbreader.book.Bookmark;
import org.geometerplus.fbreader.fbreader.FBReaderApp;
import org.geometerplus.fbreader.fbreader.FBView;

import android.content.Intent;

import com.shwread.android.qysw.activity.ReadingBookActivity;
import com.shwread.android.qysw.activity.NotesActivity;


public class SelectionRemarkAction
        extends
        FBAndroidAction
{
	
	public SelectionRemarkAction(ReadingBookActivity baseActivity, FBReaderApp fbreader) {
		super(baseActivity, fbreader);
	}
	
	@Override
	protected void run(Object... params) {
		final boolean existingBookmark;
		final Bookmark bookmark;
		
		if (params.length != 0)
		{
			existingBookmark = true;
			bookmark = (Bookmark) params[0];
		}
		else
		{
			existingBookmark = false;
			final FBView fbView = Reader.getTextView();
			final String text = fbView.getSelectedText();
			
			bookmark = new Bookmark(Reader.Model.Book, fbView.getModel().getId(), fbView.getSelectionStartPosition(), fbView.getSelectionEndPosition(), text, true, BaseActivity.contentId, BaseActivity.chapterId,3);
			fbView.clearSelection();
			
		}
		
		if(existingBookmark) {
			BaseActivity.showBookmarkPanel(bookmark);
		} else {
			final Intent intent = new Intent(BaseActivity.getApplicationContext(), NotesActivity.class);
			NotesActivity.myBookmark=bookmark;
			intent.putExtra(NotesActivity.EXISTING_BOOKMARK_KEY, existingBookmark);
			OrientationUtil.startActivity(BaseActivity, intent);
		}
		
	}
	
}
